package com.ruoyi.slip.mapper;

import java.time.LocalDateTime;
import java.util.List;
import com.ruoyi.slip.domain.SalarySlip;
import com.ruoyi.slip.domain.SalarySlipVO;
import com.ruoyi.slip.domain.tax;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 员工工资条明细Mapper接口
 * 
 * @author cxs
 * @date 2025-05-30
 */
public interface SalarySlipMapper 
{
    /**
     * 查询员工工资条明细
     * 
     * @param id 员工工资条明细主键
     * @return 员工工资条明细
     */
    public SalarySlip selectSalarySlipById(Long id);

    /**
     * 查询员工工资条明细列表
     * 
     * @param salarySlip 员工工资条明细
     * @return 员工工资条明细集合
     */
    public List<SalarySlip> selectSalarySlipList(SalarySlip salarySlip);

    /**
     * 新增员工工资条明细
     * 
     * @param salarySlip 员工工资条明细
     * @return 结果
     */
    public int insertSalarySlip(SalarySlip salarySlip);

    /**
     * 修改员工工资条明细
     * 
     * @param salarySlip 员工工资条明细
     * @return 结果
     */
    public int updateSalarySlip(SalarySlip salarySlip);

    /**
     * 删除员工工资条明细
     * 
     * @param id 员工工资条明细主键
     * @return 结果
     */
    public int deleteSalarySlipById(Long id);

    /**
     * 批量删除员工工资条明细
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteSalarySlipByIds(Long[] ids);

    /**
     * 查询员工工资条明细列表
     * @param salarySlipvo
     * @return
     */
    List<SalarySlipVO> selectList(SalarySlipVO salarySlipvo);

    /**
     * 查询基本薪资
     * @param id
     */
    @Select("select total_salary from base_salary where employee_id = #{id} and is_current = 1")
    Double selectBaseSalaryById(Long id);

    /**
     * 查询这个月请了几天假
     * @param id
     */
    @Select("select sum(duration) from leave_record where user_id = #{id} and created_at between #{startOfMonth} and #{endOfMonth}")
    double selectVocationById(@Param("id") Long id,@Param("startOfMonth") LocalDateTime startOfMonth,@Param("endOfMonth") LocalDateTime endOfMonth);

    /**
     * 获取 workedHours
     * @param id
     */
    @Select("select sum(overtime_hours) from attendance_record where user_id = #{id} and created_at between #{startOfMonth} and #{endOfMonth}")
    Double selectPlusHoursById(@Param( "id") Long id,@Param("startOfMonth") LocalDateTime startOfMonth,@Param( "endOfMonth") LocalDateTime endOfMonth);

    /**
     * 获取个人所得税
     * @param id
     */
    @Select("select ipd1.base_min personalBase,ipd1.personal_ratio personalRatio,ipd2.base_min gjjBase,ipd2.personal_ratio gjjRatio from employee\n" +
            "                    left join insurance_plan on employee.insurance_plan_id = insurance_plan.id\n" +
            "                    left join insurance_plan_detail ipd1 on insurance_plan.category_shebao_id = ipd1.category_id\n" +
            "                    left join insurance_plan_detail ipd2 on insurance_plan.category_gjj_id = ipd2.category_id where employee.id = #{id}")
    List<tax> selectPersonalTaxById(Long id);

    /**
     * 查询主键id
     * @param id
     */
    @Select("select id from salary_slip where user_id = #{id}")
    Long selectMainId(Long id);
}
